﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
using System.Text;
namespace BLL
{
    /// <summary>
    /// Summary description for Log
    /// </summary>
    public static class Log
    {
        public static void SendError()
        {
            try
            {
                Exception errorMessage = HttpContext.Current.Server.GetLastError().InnerException;
                HttpContext.Current.Server.ClearError();
                MailMessage newMail;
                newMail = new MailMessage("shop@digitalband.ru", "errors@digitalband.ru");
                newMail.Subject = string.Format("Path: {1}; IP: {0}", HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.Path);
                newMail.BodyEncoding = Encoding.UTF8;
                newMail.SubjectEncoding = Encoding.UTF8;
                StringBuilder sb = new StringBuilder();
                sb.Append(string.Format("Referrer: {0}", HttpContext.Current.Request.UrlReferrer));
                sb.Append("\n");
                sb.Append(string.Format("Uri: {0}", HttpContext.Current.Request.Url.AbsoluteUri));
                sb.Append("\n");
                sb.Append(string.Format("UserAgent: {0}", HttpContext.Current.Request.UserAgent));
                sb.Append("\n");
                sb.Append(string.Format("HTTPMethod: {0}", HttpContext.Current.Request.HttpMethod));
                sb.Append("\n");
                sb.Append("\n");
                sb.Append("\n");
                sb.Append(errorMessage.Message);
                sb.Append("\n");
                sb.Append(errorMessage.StackTrace);
                newMail.Body = sb.ToString();
                SmtpClient mail = new SmtpClient();
                mail.Send(newMail);
            }
            catch (Exception)
            {
                
            }
        }
    }
}
